<template lang="html">
  <div>
    <router-link tag="div" to="/" class="header-abs" v-show="showAbs">
      <div class="iconfont detail-back">&#xe624;</div>
    </router-link>
    <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
      <router-link to="/">
        <div class="iconfont city-detail-back">&#xe624;</div>
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
  name: "DetailHeader",
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  activated () {
    window.addEventListener("scroll", this.handleScroll)
  },
  deactivated () {
    window.removeEventListener("scroll", this.handleScroll)
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop
      if (top > 60) {
        this.showAbs = false
        const opacity = top / 140
        opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
      } else {
        this.showAbs = true
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styls/varibles.styl'
  .header-abs
    display: flex
    align-items: center
    position: absolute
    left: .2rem
    top: .2rem
    width: .8rem
    height: .8rem
    border-radius: .4rem
    background: rgba(0, 0, 0, .8)
    .detail-back
      margin-left: .16rem
      font-size: .4rem
      color: #fff
  .header-fixed
    z-index: 2
    position: fixed
    left: 0
    top: 0
    right: 0
    overflow: hidden
    height: $headerHeight
    line-height: $headerHeight
    background: $bgColor
    text-align: center
    color: #fff
    font-size: .32rem
    .city-detail-back
      position: absolute
      left: 0
      top: 0
      width: .64rem
      font-size: .4rem
      color: #fff
</style>
